//
//  LPActivityDetailsPastTableViewCell.m
//  LovingPartyBuilding
//
//  Created by 刘应平 on 2017/6/8.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPActivityDetailsPastTableViewCell.h"

@interface LPActivityDetailsPastTableViewCell ()
/**  图片   */
@property (strong, nonatomic) UIImageView  *actImageView;
/**  标题  */
@property (strong, nonatomic) UILabel  *actLabel;
/**  时间图片  */
@property (strong, nonatomic) UIImageView  *timeImageVIew;
/**  时间  */
@property (strong, nonatomic) UILabel  *timeLabel;
/**  活动类型 */
@property (strong, nonatomic) UILabel  *typeLabel;
/**  地点  */
@property (strong, nonatomic) UILabel  *addressLabel;
/**  地点图片  */
@property (strong, nonatomic) UIImageView  *addressImageView;
/**  underLin  */
@property (strong, nonatomic) UIView  *underLine;
/**  报名人数  */
@property (strong, nonatomic) UILabel  *numberLabel;

@end
@implementation LPActivityDetailsPastTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


/**  120  */
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self layoutUI];
    }
    return self;
}




#pragma mark - 界面
- (void)layoutUI{
    [self addSubview:self.actImageView];
//    [self.actImageView addSubview:self.numberLabel];
    [self addSubview:self.addressImageView];
    [self addSubview:self.addressLabel];
    //    [self.actImageView addSubview:self.typeLabel];
    [self addSubview:self.timeImageVIew];
    [self addSubview:self.timeLabel];
    
    [self addSubview:self.actLabel];
    
    
    self.actImageView.sd_layout
    .topSpaceToView(self,10 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self,12 * [UIScreen zj_screenWScale])
    .heightIs(90 * [UIScreen zj_screenHScale])
    .widthIs(130 * [UIScreen zj_screenWScale]);
    
    self.numberLabel.sd_layout
    .rightEqualToView(self.actImageView)
    .bottomEqualToView(self)
    .heightIs(25 * [UIScreen zj_screenHScale])
    .widthIs(130 * [UIScreen zj_screenWScale]);
    
    self.addressImageView.sd_layout
    .bottomEqualToView(self.actImageView)
    .leftSpaceToView(self.actImageView,10 * [UIScreen zj_screenWScale])
    .heightIs(10 * [UIScreen zj_screenHScale])
    .widthIs(10 * [UIScreen zj_screenWScale]);
    
    self.addressLabel.sd_layout
    .bottomEqualToView(self.actImageView)
    .leftSpaceToView(self.addressImageView,3 * [UIScreen zj_screenWScale])
    .heightIs(10 * [UIScreen zj_screenHScale])
    .widthIs(180 * [UIScreen zj_screenWScale]);
    
    
    self.typeLabel.sd_layout
    .topEqualToView(self.actImageView)
    .leftEqualToView(self.actImageView)
    .heightIs(30 * [UIScreen zj_screenHScale])
    .rightEqualToView(self.actImageView);
    
    self.timeImageVIew.sd_layout
    .bottomSpaceToView(self.addressImageView,10 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.addressImageView)
    .heightIs(10 * [UIScreen zj_screenHScale])
    .widthIs(10 * [UIScreen zj_screenWScale]);
    
    self.timeLabel.sd_layout
    .bottomSpaceToView(self.addressImageView,10 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.addressLabel)
    .heightIs(10 * [UIScreen zj_screenHScale])
    .widthIs(170 * [UIScreen zj_screenWScale]);
    
    
    self.underLine = [UIView new];
    self.underLine.backgroundColor = [UIColor themeGrayColor];
    [self addSubview:self.underLine];
    self.underLine.sd_layout.leftEqualToView(self).bottomEqualToView(self).widthIs([UIScreen zj_screenWith]).heightIs(1);
    
}


#pragma mark - 私有方法
- (void)setModel:(ActivityJoinDetailModel *)model{
    _model = model;
    NSString *urlString;
    if (model.COVER_JSON.count == 0) {
        urlString = @"sdfa";
    }else{
        urlString = model.COVER_JSON[0][@"file_path"];
    }
    [self.actImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,urlString]] placeholderImage:PlaceholderImage];
    if (model.SIGN_NUM.length == 0) {
        self.numberLabel.text = [NSString stringWithFormat:@"已报名%@人",@"0"];
    }else{
        self.numberLabel.text = [NSString stringWithFormat:@"已报名%@人",model.SIGN_NUM];
    }
    self.typeLabel.text = model.TAGS_NAMES;
    if (model.ADDRESS.length == 0) {
        self.addressLabel.text = @"暂无";
    }else{
        self.addressLabel.text = model.ADDRESS;
    }
    
    if (model.START_TIME.length == 0) {
        self.timeLabel.text = @"待定";
    }else{
        NSDateFormatter *dateformatter = [NSDateFormatter new];
        dateformatter.dateFormat = @"MM月dd日 HH:mm";
        NSArray *array = [model.START_TIME componentsSeparatedByString:@"."];
        self.timeLabel.text = [dateformatter stringFromDate: [NSDateFormatter dateTimeWithString:array[0]]];
        
    }
    
    CGFloat height;
    if (model.HEIGHT < 60 * [UIScreen zj_screenHScale]) {
        height = model.HEIGHT;
    }else{
        height = 60 * [UIScreen zj_screenHScale];
    }
    
    
    self.actLabel.sd_layout
    .topEqualToView(self.actImageView)
    .leftEqualToView(self.addressImageView)
    .heightIs(height)
    .widthIs([UIScreen zj_screenWith] - 172 * [UIScreen zj_screenWScale]);
    self.actLabel.attributedText = [UILabel setSpaceForLineWithText:model.DESCRIPTION lineSpace:6 * [UIScreen zj_screenHScale]];
}




#pragma mark - getter
- (UIImageView *)addressImageView{
    if (!_addressImageView) {
        _addressImageView = [UIImageView new];
        _addressImageView.contentMode = UIViewContentModeCenter;
        _addressImageView.image = [UIImage imageNamed:@"hdxq_address"];
    }
    return _addressImageView;
}


- (UIImageView *)timeImageVIew{
    if (!_timeImageVIew) {
        _timeImageVIew = [UIImageView new];
        _timeImageVIew.contentMode = UIViewContentModeCenter;
        _timeImageVIew.image = [UIImage imageNamed:@"hdxq_time"];
    }
    return _timeImageVIew;
}

- (UIImageView *)actImageView{
    if (!_actImageView) {
        _actImageView = [UIImageView new];
    }
    return _actImageView;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _timeLabel;
}

- (UILabel *)typeLabel{
    if (!_typeLabel) {
        _typeLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor zj_colorWithR:20 G:20 B:20 Al:0.3];
            label.font = [UIFont systemFontOfSize:16 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _typeLabel;
}



- (UILabel *)addressLabel{
    if (!_addressLabel) {
        _addressLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _addressLabel;
}


- (UILabel *)numberLabel{
    if (!_numberLabel) {
        _numberLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentRight;
            label.textColor = [UIColor themeColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _numberLabel;
}

- (UILabel *)actLabel{
    if (!_actLabel) {
        _actLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.numberOfLines = 0;
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:15 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _actLabel;
}

- (void)setIsNoData:(BOOL)isNoData{
    _isNoData = isNoData;
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], 80 * [UIScreen zj_screenHScale])];
    label.font = [UIFont systemFontOfSize:16 * [UIScreen zj_textFontScale]];
    label.textColor = [UIColor textBlackColor];
    label.text = @"暂无往期回顾";
    label.backgroundColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label];
}

- (void)setIsLastCell:(BOOL)isLastCell{
    _isLastCell = isLastCell;
    self.underLine.hidden = YES;
    TenGrayShadowView *ten = [TenGrayShadowView new];
    ten.backgroundColor = [UIColor themeGrayColor];
    [self addSubview:ten];
    ten.sd_layout.bottomEqualToView(self)
    .leftEqualToView(self)
    .rightEqualToView(self)
    .heightIs(10 * [UIScreen zj_screenHScale]);
}

@end
